package com.sunl.mall.ali.mq.springboot.producer;

import com.alibaba.fastjson.JSONObject;
import com.sunl.mall.ali.mq.model.RocketMqMessageBody;
import com.sunl.mall.ali.mq.model.RocketMqMessageWrapper;
import com.sunl.mall.ali.mq.producer.RocketMqProducerBean;
import com.sunl.mall.common.api.topic.MqTopic;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CommonProducer {

    @Resource(name = "defaultProducer")
    private RocketMqProducerBean defaultProducer;

    public void sendCommonMq() {
        RocketMqMessageWrapper<String> msg = new RocketMqMessageWrapper<>(MqTopic.COMMON_MSG,
                RocketMqMessageBody.getInstance("我是消息体"));
        defaultProducer.send(msg, JSONObject::toJSONBytes);
    }
}
